package com.yayan.xh.service;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.yayan.xh.bean.BannerBean;
import com.yayan.xh.dao.BannerDao;
import com.yayan.xh.dao.IBannerDao;

@Service
public class BannerService implements IBannerService {
	
	private IBannerDao bannerDao;
	
	public BannerService() {
		bannerDao = new BannerDao();
	}

	@Override
	public List<BannerBean> getBanner(Map<String, String> map) {
		List<BannerBean> result = null;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))) {
				result = bannerDao.getBanner(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public BannerBean getBannerById(Map<String, String> map) {
		BannerBean result = null;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))
					&& null != map.get("bId") && !"0".equalsIgnoreCase(map.get("bId"))) {
				result = bannerDao.getBannerById(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public boolean saveBanner(Map<String, String> map) {
		boolean f = false;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))
					&& null != map.get("type") && null != map.get("link") && null != map.get("linkName") && null != map.get("img")) {
				f = bannerDao.saveBanner(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return f;
	}

	@Override
	public boolean delBanner(Map<String, String> map) {
		boolean f = false;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))
					&& null != map.get("bId") && !"0".equalsIgnoreCase(map.get("bId"))) {
				f = bannerDao.delBanner(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return f;
	}

	@Override
	public boolean modifyBanner(Map<String, String> map) {
		boolean f = false;
		try {
			if(null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))
					&& null != map.get("bId") && !"0".equalsIgnoreCase(map.get("bId"))
					&& null != map.get("type") && null != map.get("link") && null != map.get("linkName") && null != map.get("img")) {
				f = bannerDao.modifyBanner(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return f;
	}

	@Override
	public List<Map<String, Object>> getBannerList(Map<String, String> map) {
		List<Map<String, Object>> list = null;
		try {
			if( null != map.get("shopId") && !"0".equalsIgnoreCase(map.get("shopId"))) {
				list = bannerDao.getBannerList(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

}
